<template>
  <view :style="{ paddingTop: vuex_custom_bar_height + 'px' }" class="page_diy_list page_dormitory_information_list container">
	<view class="content">
	  <tn-nav-bar>宿舍信息列表</tn-nav-bar>
	  <view class="page-list" id="page_diy_list">
	        <!-- 筛选模块(开始) -->
	        <view class="search-wrap">
	  	    	      	          <Search v-model="query.dormitory_name" placeholder="搜索宿舍名称" @search="search_" @cancel="search_cancel('dormitory_name')" @input="(val) => inputValue(val, 'dormitory_name')" />
	      	    	  	    	      	          <Search v-model="query.name_of_dormitory_manager" placeholder="搜索宿管姓名" @search="search_" @cancel="search_cancel('name_of_dormitory_manager')" @input="(val) => inputValue(val, 'name_of_dormitory_manager')" />
	      	    	  	    	  	    	  	    	  	    	  	    	  	  	    	      	    	  	    	      	    	  	    	  	    	  	    	  	    	  	    	  	  	          <MeDropdown
	            :menuList.sync="menuList"
	            themeColor="#0079fe"
	            :duration="300"
	            :isCeiling="true"
	            @onConfirm="onConfirmDropdown"
	            @onChange="onChangeDropdown"
	          ></MeDropdown>
	        </view>
	  
	        <!-- 筛选模块(结束) -->
	  <!-- 列表 -->
	        <view class="customized-list">
	  	          <view v-for="(o, i) in list" :key="i" class="customized-item">
	  	  	            <view
	              class="customized-item-body"
	              @click=" $navTo('/pagesC/dormitory_information/details?dormitory_information_id=' + o['dormitory_information_id'])">
	  	              <view class="item-row " v-if="1 && $check_field('get', 'dormitory_name')">
	                <view class="label" v-if="true">
	                  <span>宿舍名称</span>
	                </view>
	    	                <view class="value">
	                  <span>{{ o['dormitory_name'] }}</span>
	                </view>
	    	              </view>
	  	              <view class="item-row " v-if="1 && $check_field('get', 'name_of_dormitory_manager')">
	                <view class="label" v-if="true">
	                  <span>宿管姓名</span>
	                </view>
	    	                <view class="value">
	                  <span>{{ o['name_of_dormitory_manager'] }}</span>
	                </view>
	    	              </view>
	  	              <!-- <view class="item-row " v-if="1 && $check_field('get', 'dormitory_location')">
	                <view class="label" v-if="true">
	                  <span>宿舍位置</span>
	                </view>
	    	                <view class="value">
	                  <span>{{ o['dormitory_location'] }}</span>
	                </view>
	    	              </view> -->
	  	              <view class="item-row diy-image" v-if="1 && $check_field('get', 'cover_photo')">
	                <view class="label" v-if=" false">
	                  <span>封面图片</span>
	                </view>
	    	                <view class="value diy_img">
	                  <image :src="$fullImgUrl(o['cover_photo'])" width="100%" height="100" />
	                </view>
	    	              </view>
	  	              <view class="item-row " v-if="0 && $check_field('get', 'dormitory_building')">
	                <view class="label" v-if="true">
	                  <span>宿舍楼栋</span>
	                </view>
	    	                <view class="value">
	                  <span>{{ o['dormitory_building'] }}</span>
	                </view>
	    	              </view>
	  	              <view class="item-row " v-if="0 && $check_field('get', 'number_of_residents')">
	                <view class="label" v-if="true">
	                  <span>居住人数</span>
	                </view>
	    	                <view class="value">
	                  <span>{{ o['number_of_residents'] }}</span>
	                </view>
	    	              </view>
	  	              <!-- <view class="item-row " v-if="0 && $check_field('get', 'dormitory_details')">
	                <view class="label" v-if="true">
	                  <span>宿舍详情</span>
	                </view>
	    	                <view class="value">
	                  <span>{{ o['dormitory_details'] }}</span>
	                </view>
	    	              </view> -->
	  	  	            </view>
	  
	  	            <view class="customized-item-footer">
	    	              <view class="praise">
	                <text class="icon iconfont icon-dianzan"></text>
	                {{ o['praise_len'] || 0 }}
	              </view>
	    	    	              <view class="collect">
	                <text class="icon iconfont icon-shoucang"></text>
	                {{ o['collect_len'] || 0 }}
	              </view>
	    	    	              <view class="comment">
	                <text class="icon iconfont icon-pinglun"></text>
	                {{ o['comment_len'] || 0 }}
	              </view>
	    	            </view>
	  	  	          </view>
	        </view>
	  
	        <!-- /列表 -->
	        <!-- 分页器 -->
	        <uni-pagination
	          class="pager"
	          show-icon="true"
	          :total="count"
	          :pageSize="query.size"
	          :current="query.page"
	          @change="page_change"
	        ></uni-pagination>
	        <!-- /分页器 -->
	  	      </view>
	    </view>
	</view>
</template>

<script>
import Search from '@/components/businessCp/search.vue';
import mixin from '@/libs/mixins/page.js';
import MeDropdown from '../components/me-dropdown/index.vue';

export default {
  mixins: [mixin],
  components: {
    Search,
    MeDropdown,
  },
  data() {
    return {
      url_get_list: '~/api/dormitory_information/get_list?like=0',
                                  query: {
                dormitory_name: "", // 宿舍名称
                        name_of_dormitory_manager: "", // 宿管姓名
                          dormitory_information_id: 0, // ID
        page: 1,
        size: 10,
      },
      list: [],
      count: 50,
      menuList: [
                      {
            title: '点赞数',
            type: 'sort',
            command: '`praise_len`',
            value: 0,
        },
        {
            title: '点击数',
            type: 'sort',
            command: '`hits`',
            value: 0,
        },
        {
            title: '收藏数',
            type: 'sort',
            command: '`collect_len`',
            value: 0,
        },
        {
            title: '发布时间',
            type: 'sort',
            command: '`create_time`',
            value: 0,
        }
      ],
    };
  },
  methods: {
    onConfirmDropdown(val) {
      if (val.value) {
        this.query.orderby = val.command + ' ' + val.value;
      } else {
        this.query.orderby = '';
      }
      this.search_();
    },
    onChangeDropdown(v) {},
    /**
     * 获取列表后
     * @param {Object} json
     * @param {Object} func
     */
    get_list_after(json, func) {
      let list = json.result.list;
      this.get_praise(list);
      if (func) {
        func(json);
      }
    },
    /**
     * 获取点赞数
     * @param {Object} list
     */
    get_praise(list) {
		for (let i = 0; i < list.length; i++) {
			list[i].praise_len = 0;
		}
		this.$get('~/api/praise/list_group?groupby=source_id&source_table=dormitory_information',{},(res) => {
		    if (res.result && res.result.list) {
		      res.result.list.map((o) => {
		        for (var i = 0; i < list.length; i++) {
		          var oj = list[i];
		          if (oj['dormitory_information_id'] === o['source_id']) {
		            oj['praise_len'] = o['count'];
		            // break;
		          }
		        }
		      });
		    } else if (res.error) {
		      console.error(res.error);
		    }
		  }
		);
    },
          
              
      
      
      
      
      
        search_() {
      this.query.page = 1;
      this.get_list();
    },
    search_cancel(key) {
      this.query[key] = '';
      this.search_();
    },
	inputValue(val, key) {
	  this.query[key] = val;
	  this.search_();
	},
  },
  created() {
                              },
};
</script>

<style lang="scss" scoped>
  @import '../../styles/pagesC/index.scss';
</style>